Skip to content

feat(logger): introduce loglevel constant #2787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

marlapativ
Copy link
Contributor

Summary

Changes

This PR converts the existing LogLevel type definition to a more concise and maintainable enum-like structure using a const object. It also simplifies the LogLevel type to utilize this new structure.

Introduced a new LogLevel const object in packages/logger/src/constants.ts:

const LogLevel = {
  DEBUG: 'DEBUG',
  INFO: 'INFO',
  WARN: 'WARN',
  ERROR: 'ERROR',
  SILENT: 'SILENT',
  CRITICAL: 'CRITICAL',
} as const;

Imported the constants in packages/logger/src/types/Log.ts and replace the existing types

+import { LogLevel } from '../constants.js';

- type LogLevelDebug = 'DEBUG';
- type LogLevelInfo = 'INFO';
- type LogLevelWarn = 'WARN';
- type LogLevelError = 'ERROR';
- type LogLevelSilent = 'SILENT';
- type LogLevelCritical = 'CRITICAL';

type LogLevel =
-   | LogLevelDebug
-   | Lowercase<LogLevelDebug>
-   | LogLevelInfo
-   | Lowercase<LogLevelInfo>
-   | LogLevelWarn
-   | Lowercase<LogLevelWarn>
-   | LogLevelError
-   | Lowercase<LogLevelError>
-   | LogLevelSilent
-   | Lowercase<LogLevelSilent>
-   | LogLevelCritical
-   | Lowercase<LogLevelCritical>;
+   | (typeof LogLevel)[keyof typeof LogLevel]
+   | Lowercase<(typeof LogLevel)[keyof typeof LogLevel]>;

Usage

The newly introduced constants can be used to set the log level for the logger.
Example:

const logger = new Logger({
  logLevel: LogLevel.DEBUG,
});

Issue number: #2780


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@marlapativ marlapativ requested a review from a team July 20, 2024 17:30
@marlapativ marlapativ requested a review from a team as a code owner July 20, 2024 17:30
@boring-cyborg boring-cyborg bot added logger This item relates to the Logger Utility tests PRs that add or change tests labels Jul 20, 2024
Copy link

boring-cyborg bot commented Jul 20, 2024

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Jul 20, 2024
@dreamorosi dreamorosi linked an issue Jul 20, 2024 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Jul 20, 2024
@dreamorosi
Copy link
Contributor

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the quick PR!

Appreciate it 🎉

@dreamorosi dreamorosi merged commit e75f593 into aws-powertools:main Jul 20, 2024
17 checks passed
Copy link

boring-cyborg bot commented Jul 20, 2024

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes logger This item relates to the Logger Utility size/M PR between 30-99 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: export LogLevel values as object
2 participants